package com.ygqh.baby.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.mapper.KsdOrderDetailMapper;
import com.ygqh.baby.po.KsdOrderDetail;
import com.ygqh.baby.po.KsdOrderDetailExample;
import com.ygqh.baby.service.KsdOrderDetailService;

@Service
public class KsdOrderDetailServiceImpl implements KsdOrderDetailService {

	@Autowired
	private KsdOrderDetailMapper ksdOrderDetailMapper;

	@Override
	public List<KsdOrderDetail> find() {
		KsdOrderDetailExample example = new KsdOrderDetailExample();
		example.createCriteria();
		return ksdOrderDetailMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		KsdOrderDetailExample example = new KsdOrderDetailExample();
		example.createCriteria();
		return ksdOrderDetailMapper.countByExample(example);
	}

	@Override
	public KsdOrderDetail findById(Long id) {
		return ksdOrderDetailMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(KsdOrderDetail ksdOrderDetail) {
		return ksdOrderDetailMapper.insertSelective(ksdOrderDetail);
	}

	@Override
	public int update(KsdOrderDetail ksdOrderDetail) {
		return ksdOrderDetailMapper.updateByPrimaryKeySelective(ksdOrderDetail);
	}

	@Override
	public ResultSet<KsdOrderDetail> search(QueryInfo queryInfo, String q) {
		List<KsdOrderDetail> list = ksdOrderDetailMapper.selectSuper(queryInfo, q);
		int count = ksdOrderDetailMapper.countSuper(q);
		ResultSet<KsdOrderDetail> resultSet = new ResultSet<KsdOrderDetail>(count, list);
		return resultSet;
	}

	@Override
	public int saveOrUpdate(KsdOrderDetail ksdOrderDetail) {
		int r = 0;
		if (ksdOrderDetail.getId() != null) {
			r = this.update(ksdOrderDetail);
		} else {
			r = this.save(ksdOrderDetail);
		}
		return r;
	}

	@Override
	public int saveDetailBatch(List<KsdOrderDetail> details) {
		return ksdOrderDetailMapper.saveDetailBatch(details);
	}

	@Override
	public List<KsdOrderDetail> findByOrderId(Long orderId) {
		return ksdOrderDetailMapper.selectByOrderId(orderId);
	}

}
